<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Register</title>
	<script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
	<!-- 导入validate插件 -->
	<script type="text/javascript" src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script>
	<script type="text/javascript" src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/localization/messages_zh.js"></script>
	<script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/localization/messages_zh.js"></script>
	<!-- 用JQuery写 -->
	<link rel="stylesheet" type="text/css" href="../css/register.css">
	<script type="text/javascript" src="../js/register.js"></script>
	<meta id="viewport" name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1,initial-scale=1,user-scalable=no">
	<script src="https://cdn1.lncld.net/static/js/av-min-1.2.1.js"></script>
	<script type="text/javascript" src="../js/utils.js"></script>


</head>
<body>
<div class="register">
	<form id="Myform">
		<div>
			<div>
				<div class="register-vertification">
					<div id="number">
				   	   <img id="img-phone" src="../images/phone.jpg">
					   <input class="vertification" id="phonenumber" type="text" name="phonenumber" placeholder="中国大陆手机号" style="background:white" >
					   <label id="get-vertification">获取验证码</label>
					</div>
					<!-- <div
					<input type="text" id="getnumber" name="number" placeholder="获取验证码" >
					</div> -->
				    <div id="vertification-number">
				        <img id="img-key" src="../images/key.jpg">
				        <input type="text" class="vertification" name="vertificationnumber" id="vertificationnumber" placeholder="输入验证码" >
					</div>
				</div>
				<div class="hint">
					<div id="agree">绑定账号行为表示您同意</div>
					<div id="explain">《隐私说明》</div>
				</div>
			</div>
			<div id="button">
				<button id="register-button"  type="button">登 录</button>
			</div>
		</div>
	</form>
	<div>
		<label id="errormessage"></label>
	</div>
</div>

	<script>
		$(document).ready(function() {
			var APP_ID = 'EYUJxAnbWFjD68lcAfM6XQ1c-gzGzoHsz';
			var APP_KEY = 'iRAucgXYzfnSPHtF4z1Wq9ny';
			AV.init({
				appId: APP_ID,
				appKey: APP_KEY
			});

			var TestObject = AV.Object.extend('TestObject');
			var testObject = new TestObject();
			testObject.save({
				words: 'Hello World!'
			}).then(function (object) {
				alert('LeanCloud Rocks!');
			})
			var countdown = 60
			var vLabel = $('#get-vertification')

			$('#get-vertification').bind("click",touch)


			function settime() {
				if (countdown == 0) {
					vLabel.attr("disabled","false");
					vLabel.html("获取验证码");
					$('#get-vertification').bind("click",touch)
					countdown = 60;
				} else {
					vLabel.attr("disabled", true);
					vLabel.html("重新发送(" + countdown + ")");

					countdown--;
				}
				$('#get-vertification').unbind("click",touch)
				setTimeout(function () {
					settime(vLabel)
				}, 1000)

			}

			function touch() {
				if (!$('#phonenumber').val() == ""){
					settime()
					AV.Cloud.requestSmsCode($('#phonenumber')[0].value).then(function (success) {
						alert(success)
					}, function (error) {
						alert(error)
					});
				}

			}

			// $('#register-button').click(function(){
			// 	alert("........")
			// 	var dataInfo ={
			// 		phonenumber:$('#phonenumber')[0].value
			// 	}
			// 	$.ajax({
			// 		url:"/hibook/saveInBackground.do",
			// 		method:'POST',
			// 		data:dataInfo,
			// 		success:function(result){
			// 			alert("result:"+result)
			// 			responesToPhone("true")
			// 		},
			// 		error:function(){
			// 			alert("ajax出错")
			// 		}
			// 	})
			$('#register-button').click(function() {
				AjaxIO.post("/saveInBackground", {
						phonenumber:$('#phonenumber')[0].value
					},
					function(result) {
						responesToPhone("true")

					});


			
//				AV.User.signUpOrlogInWithMobilePhone($('#phonenumber')[0].value, $("#vertificationnumber")[0].value).then(function (success) {
//					// 成功
//					alert("成功")
//					var dataInfo ={
//						phonenumber:$('#phonenumber')[0].value
//					}
//
//					$.ajax({
//						url:"/hibook/saveInBackground.do",
//						method:'POST',
//						data:dataInfo,
//						success:function(result){
//							alert("result:"+result)
//							responesToPhone("true")
//						},
//						error:function(){
//							alert("ajax出错")
//						}
//					})
//
//				}, function (error) {
//					// 失败
//					alert("失败")
//				});
			})

		})
		function responesToPhone(isSuccess){
			alert("运行了")
			window.webkit.messageHandlers.responesToPhone.postMessage(isSuccess);
		}

	</script>
</body>
</html>